<?php include TMPL_PATH.'public/header.phtml';?>
<div class="subnav">
    <div class="content-menu ib-a blue line-x" style="overflow:hidden;">
    	<div style="float:left;margin-right:50px;">
        <a href='javascript:;' class="on"><em>产品列表</em></a><span>|</span>
        <a href='<?php echo U('product/add');?>' ><em>添加产品</em></a>
      </div>
    	<div style="color:#000;">
		<div style="float:left;">
    		<form name="searchform" action="<?php echo U('product/index');?>"  method="post">
    		<input type="hidden" value="1" name="search">
    		产品分类：<select name="catid" id="catid">
    		<option value=''>≡ 全部分类  ≡</option>
    		<option value='9999' <?php echo isset($search)&& $search['catid']==9999 ? 'selected' :null?>>≡ 未分类产品  ≡</option>
				<?php echo $select_categorys;?>
				</select>
                &nbsp;&nbsp;&nbsp;产品类型：<select name="modelid" id="modelid">
				 	<option value=''>≡ 全部类型  ≡</option>
				 	<?php 
				 	if (isset($modelList) && $modelList):
				 		foreach ($modelList as $key => $val):
				 	?>
				 	<option value='<?php echo $key?>' <?php if($key==$modelid)echo 'selected';?>><?php echo $val;?></option>
				 	<?php 
				 		endforeach;
				 	endif;
				 	?>
				 </select>
                 &nbsp;&nbsp;设计师：<select name="designer_id" id="designer_id">
				 	<option value='-1' <?php if($designer_id==-1)echo 'selected';?>>全部</option>
				 	<option value='0' <?php if($designer_id==0)echo 'selected';?>>自已团队</option>
				 	<?php 
				 	
				 	if (isset($designerList) && $designerList):
				 		foreach ($designerList as $key => $val):
				 	?>
				 	<option value='<?php echo $key?>' <?php if($key==$designer_id)echo 'selected';?>><?php echo $val['username'];?></option>
				 	<?php 
				 		endforeach;
				 	endif;
				 	?>
				 </select>
				 &nbsp;&nbsp;&nbsp;显示状态：<select name="display" id="display">
				 	<option value=''>≡ 全部  ≡</option>
				 	<option value='0' <?php if('0'==$display)echo 'selected';?>>下架</option>
					<option value='1' <?php if('1'==$display)echo 'selected';?>>上架</option>
				 </select>
                 &nbsp;&nbsp;&nbsp;预售：<select name="product_type" id="product_type">
				 	<option value='' <?php if($product_type=='')echo 'selected';?>>全部</option>
				 	<option value='1' <?php if($product_type==1)echo 'selected';?>>是</option>
					<option value='0' <?php if($product_type==0 && $product_type !='')echo 'selected';?>>否</option>
				 </select>
                &nbsp;&nbsp;&nbsp;<select name="searchtype" id="searchtype">
					<!--<option <?php //if($searchtype==0)echo 'selected';?> value="0">名称</option>-->
                    <option value="3" <?php if($searchtype==3 || $searchtype==0)echo 'selected';?>>货号</option>
					<option <?php if($searchtype==1)echo 'selected';?> value="1">编号</option>
					<option value="2" <?php if($searchtype==2)echo 'selected';?>>ID</option>
                    <option value="4" <?php if($searchtype==4)echo 'selected';?>>关键字</option>
				</select>
				<input type="text" class="input-text" style="width:200px" value="<?php echo $keyword;?>" name="keyword" id="keyword">
				<input type="submit" value="搜索" class="button" name="search">
    		</form></div>
    		<div style="float:right;">
                 <a href="javascript:carProductExcel();">导出Excel</a>
			</div>
    	</div>
    </div>
</div>
<div class="bk"></div>
<form action="<?php echo U('product/beach_select_edit');?>" method="post" name="myform"  id="myform">
<div class="pad_10">
<div class="table-list">
    <table width="100%" cellspacing="0" >
        <thead>
            <tr>
            <th width="20" align="center"><input type="checkbox" value="" id="check_box" onclick="selectall('pids[]');"></th>
<!--            <th width="30">排序</th>-->
            <th width="20"><a href="javascript:sortTable('id','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">ID<?php if($order_by=='id')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
            <th width="80"><a href="javascript:sortTable('eng_id','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">货号<?php if($order_by=='eng_id')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
            <th width="80"><a href="javascript:sortTable('sn','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">编号<?php if($order_by=='sn')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
			<th width="80">面料编号</th>
			<th width="80">缩略图</th>
			<th width="200" align='left'><a href="javascript:sortTable('name','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">产品名称<?php if($order_by=='name')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
            <?php if($is_accessories):?><th align='center' width="50">库存</th><?php endif;?>
            <th align='center' width="50">分类名称</th>
			<th align='center' width="50"><a href="javascript:sortTable('product_type','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">是否预售<?php if($order_by=='product_type')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
<!--            <th align='center' width="80">品牌</th>-->
            <th align='center' width="50"><a href="javascript:sortTable('sell_price','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">成衣价<?php if($order_by=='sell_price')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
            <th align='center' width="50"><a href="javascript:sortTable('custom_price','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">正常价<?php if($order_by=='custom_price')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
            <th align='center' width="50"><a href="javascript:sortTable('advanced_price','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">定制价<?php if($order_by=='advanced_price')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
<!--            <th align='center' width="50">库存</th>-->
            <th align='center' width="50"><a href="javascript:sortTable('visit','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">访问量<?php if($order_by=='visit')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
             <th align='center' width="50"><a href="javascript:sortTable('sorts','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">排序<?php if($order_by=='sorts')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
            <th align='center' width="50"><a href="javascript:sortTable('display','<?php echo $sort_by=='ASC' ? 'DESC':'ASC'?>')">上架<?php if($order_by=='display')echo "<img src='../Public/images/sort_".strtolower($sort_by).".gif'>"; ?></a></th>
<!--            <th align='center' width="30">销售</th>-->
						<th align='center' width="100">管理操作</th>
            </tr>
        </thead>
    <tbody>
    <?php 
   	if(isset($productList) && $productList):
   		foreach ($productList as $v):
   		$supplier_name=D("suppliers")->where(array('suppliers_id'=>$v['suppliers_id']))->getField("suppliers_name");
   ?>
			<tr>
				<td align="center"><input type="checkbox" name="pids[]" value="<?php echo $v['id'];?>"></td>
<!--					<td align='center'><input id="listorder-<?php echo $v['id']?>" name='listorders[<?php echo $v['id']?>]' type='text' size='3' title="当光标离开输入框后修改排序" value='<?php echo $v['listorder']?>' onblur="javascript:setting_listorder(<?php echo $v['id']?>);" class='input-text-c'></td>-->
					<td align='center'><?php echo $v['id']?></td>
                   <td align='center'><?php echo $v['eng_id']?></td>
					<td align='center'><?php echo $v['sn']?></td>
					<td align='center'><?php echo $supplier_name;?></td>
					<td align='center'><img src="<?php echo $v['small_img']?>"></td>
					 <?php 
						if($v['is_translate']==1){
							$url = "http://". $_SERVER['HTTP_HOST']."/1-suit-1-shirt";
						}else{
							$url = "http://". $_SERVER['HTTP_HOST']."/product/".$v['id']."-blue-jacquard-shirt";
						}
					?>
					<td><?php echo $v['name']?>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php if($v['display'] == 1){ ?><a href="<?php echo $url;?>" target="_blank"><font color="red">点击查看</font></a><?php } ?></td>
					<?php if($is_accessories):?><td align='center'><?php echo $v['surplus'];?></th><?php endif;?>
                    <td align='center'><?php echo $v['catname'];?></td>
<!--					<td align='center'><?php echo $v['brand_name'];?></td>-->
					<td align='center'>
						<?php if($v['product_type']> 0):?>
						是
						<?php else:?>
						否
						<?php endif;?>
					</td>
					<td align='center'><?php echo $v['sell_price']?></td>
					<td align='center'><?php echo $v['custom_price']?></td>
					<td align='center'><?php echo $v['advanced_price']?></td>
<!--					<td align='center'><?php echo $v['stock']?></td>-->
					<td align='center'><?php echo $v['visit']?></td>
					<td align='center'>
						<span id="s<?php echo $v['id']?>" onclick="setss(<?php echo $v['id']?>);">
							<?php echo $v['sorts']?>
						</span>
						<span id="t<?php echo $v['id']?>" style="display:none;">	
							<input type="text" size="10" name="v<?php echo $v['id']?>" id="v<?php echo $v['id']?>" value="<?php echo $v['sorts']?>" onblur="update(<?php echo $v['id']?>,this.value);" style="text-align:center;" />
						</span>
					</td>
					<td align='center' id="status-<?php echo $v['id']?>"><?php //echo $v['display'] ? '<font color="red">√</font>' : '<font color="blue">×</font>';?>
<!--					<?php if($v['display']):?>
					<a href="javascript:setting_status(<?php echo $v['id']?>,0);"><font color="red">√</font></a>
					<?php else:?>
					<a href="javascript:setting_status(<?php echo $v['id']?>,1);"><font color="blue">×</font></a>
					<?php endif;?>-->
                    
                    <select name="product_status" class="product_status">
                       <option value="<?php echo $v['id']?>#0" <?php if($v['display'] == 0) echo "selected"?> >下架</option>
                       <option value="<?php echo $v['id']?>#1" <?php if($v['display'] == 1) echo "selected"?> >上架</option>
                       <option value="<?php echo $v['id']?>#2" <?php if($v['display'] == 2) echo "selected"?> >补货</option>
                    </select>
					</td>
<!--					<td align='center'><?php echo $v['is_sell'] ? '<font color="red">√</font>' : '<font color="blue">×</font>';?></td>-->
					<td align='center'>
                    <?php if($is_accessories):?>
                        <a href="<?php echo U('suppliers/inventory_add', array('tid' => $v['id'], 'type'=>2));?>">新增记录</a> |
                        <a href="<?php echo U('suppliers/inventory', array('tid' => $v['id'], 'type'=>2));?>">用料记录</a> <br />                     
                    <?php endif;?> 
					<a href="<?php echo U('product/edit', 'pid='.$v['id']);?>">修改</a> | 
					<a href="javascript:confirmurl('<?php echo U('product/product_trach_add', 'pid='.$v['id']);?>','确认要移动到回收站 『<?php echo $v['name']?>』 吗？')">回收站</a>
					</td>
				</tr>
	<?php 
		endforeach;
		endif;
	?>
   </tbody>
    </table>
<div class="btn">
     <select name="type" id="selAction" onchange="changeAction()">
    <option value="">请选择...</option>
    <option value="trash">回收站</option>
    <option value="on_sale">上架</option>
    <option value="not_on_sale">下架</option>
    <?php 
			if (isset($recommendArray) && $recommendArray):
				foreach ($recommendArray as $key => $val):
		?>
    <option value="<?php echo $key;?>"><?php echo $val;?></option>
    <option value="<?php echo $key;?>_no">取消<?php echo $val;?></option>
    <?php 
    		endforeach;
    	endif;
    ?>
    <option value="move_to">转移到分类</option>
<!--	  <option value="suppliers_move_to">转移到供货商</option>-->
  </select>
  <select name="catid" id="selectCategory" style="display:none"><option value="0">请选择...</option>
				<?php echo $select_categorys;?>
				</select>
	<input type="submit" class="button" name="dosubmit" value="批处理" />
	
	
	</div> 
</div>
</div>
</form>
<div id="pages"><?php echo $pageShow;?></div>
</body>
</html>
<script type="text/javascript">
<!--
function setting_listorder(id){
	var lisobj = $('#listorder-'+id);
	listorder = parseInt(lisobj.val());
	if(isNaN(listorder)){
		alert('排序只能设置为整数.');return;
	}
	$.get('<?php echo U('product/change_listorder_ajax');?>',{pid:id,listorder:listorder},function(data){
		if(data==1){lisobj.val(listorder)}
	});
}

function carProductExcel(){
    var hrefstr ="<?php echo U('product/index');?>"
                     +"&doexcel=1"
                     +"&catid="+$('#catid').val()
                     +"&designer_id="+$('#designer_id').val()
                     +"&display="+$('#display').val()
                     +"&product_type="+$('#product_type').val()
                     +"&searchtype="+$('#searchtype').val()
                     +"&keyword="+$('#keyword').val();
    location.href = hrefstr;
}
function setting_status(id,display){
	$.get('<?php echo U('product/change_status_ajax');?>',{pid:id,display:display},function(){
			if(display==0){
				$('#status-'+id).html('<a href="javascript:setting_status('+id+',1);"><font color="blue">×</font></a>');
			}else{
				$('#status-'+id).html('<a href="javascript:setting_status('+id+',0);"><font color="red">√</font></a>');
			}
		});
}
$('.product_status').change(function(){
    var product_status = $(this).val();
	var strs= new Array(); //定义一数组 
	strs=product_status.split("#"); //字符分割
	$.get('<?php echo U('product/change_status_ajax');?>',{pid:strs[0],display:strs[1]},function(){
	})
})
function changeAction()
{
	ctype = $('#selAction').val();
	if(ctype == 'move_to'){
		$('#selectCategory').css('display','');
	}else{
		$('#selectCategory').css('display','none');
	}
}
function productTypeUrl()
{
	var s=document.getElementById("select").value; 
	
	window.location.href='<?php echo U('product/index');?>&product_type='+s; 
}
function setss(id){
	document.getElementById("s"+id).style.display="none";
	document.getElementById("t"+id).style.display="";
	document.getElementById("v"+id).focus();
}
function update(id,val){
	var numb=/^[1-9]\d{0,2}$/;
	if(!numb.test(val)){dialog_tis('提示','请输入1到999之间的数字',2);return;}

	var s_val = document.getElementById("s"+id).innerHTML;
	if(parseInt(s_val) == parseInt(val)){
		document.getElementById("s"+id).style.display="";
		document.getElementById("t"+id).style.display="none";
        return;
	}
	$.post("<?php echo U('product/edit_sort_ajax');?>",{id:id,val:val},function(result){
    	if(result==1){
			//dialog_tis('提示','修改成功',1);
			document.getElementById("s"+id).innerHTML=val;
			document.getElementById("s"+id).style.display="";
			document.getElementById("t"+id).style.display="none";
		}else{
			dialog_tis('提示','修改失败',1);
			document.getElementById("v"+id).innerHTML=s_val;
			document.getElementById("s"+id).style.display="";
			document.getElementById("t"+id).style.display="none";
		}
  	});
}
function dialog_tis(title,content,time){
	window.top.art.dialog({title: title,content:content,lock:'false',drag: false,resize: false,time:time});
}
//-->
</script>